<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAdminTables extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function getConnection()
    {
        return config('admin.database.connection') ?: config('database.default');
    }

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create(config('admin.database.users_table'), function (Blueprint $table) {
            $table->increments('id');
            $table->string('username', 190)->unique();
            $table->string('password', 60);
            $table->string('name');
            $table->string('avatar')->nullable();
            $table->string('remember_token', 100)->nullable();

            $table->string('key')->comment('唯一码')->unique();
            $table->integer('sensitivity_ability')->default('1')->comment('敏感能力');
            $table->string('email')->default('')->comment('邮箱')->index();
            $table->integer('score_count')->default(0)->comment('积分数')->index();
            $table->integer('topic_count')->default(0)->comment('发帖数')->index();
            $table->integer('comment_count')->default(0)->comment('回复数')->index();
            $table->integer('following_count')->default(0)->comment('关注数')->index();
            $table->integer('fans_count')->default(0)->comment('粉丝数')->index();
            $table->string('register_source')->nullable()->comment('注册来源');

            $table->timestamps();
        });

        Schema::create(config('admin.database.menu_table'), function (Blueprint $table) {
            $table->increments('id');
            $table->integer('parent_id')->default(0);
            $table->integer('order')->default(0);
            $table->string('title', 50);
            $table->string('icon', 50);
            $table->string('uri')->nullable();

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists(config('admin.database.users_table'));
        Schema::dropIfExists(config('admin.database.menu_table'));
    }
}
